<template>
  <view class="userinfo">
    <view class="input-items">
      <text class="tit">单位名称</text>
      <input
        type="text"
        v-model="unitinfo.unit_name"
        placeholder="请输入单位名称"
        placeholder-class="unit-text"
      />
    </view>
    <view class="input-items">
      <text class="tit">单位地址</text>
      <input
        type="text"
        v-model="unitinfo.unit_address"
        placeholder="请输入单位地址"
        placeholder-class="unit-text"
      />
    </view>
    <view class="input-items">
      <text class="tit">单位电话</text>
      <input
        type="text"
        placeholder="请输入单位电话"
        v-model="unitinfo.unit_phone"
        placeholder-class="unit-text"
      />
    </view>
    <view class="input-items">
      <text class="tit">老板姓名</text>
      <input
        type="text"
        v-model="unitinfo.boos_name"
        placeholder="请输入老板姓名"
        placeholder-class="unit-text"
      />
    </view>
    <view class="input-items">
      <text class="tit">经营面积</text>
      <input
        type="text"
        v-model="unitinfo.area"
        placeholder="请输入经营面积"
        placeholder-class="unit-text"
      />
    </view>
    <view class="btn-wrapper">
      <button class="add-btn" @tap="handleClick">提交</button>
    </view>
    <!--加载动画-->
    <rfLoading isFullScreen :active="loading"></rfLoading>
  </view>
</template>

<script>
import { userDetail } from "@/api/userInfo";
export default {
  components: {},
  data() {
    return {
      loading: false,
      unitinfo: {
        area: "",
        boos_name: "",
        id: null,
        unit_address: "",
        unit_name: "",
        unit_phone: "",
      },
    };
  },
  onLoad(option) {
    this.initData(option.id);
  },
  methods: {
    // 通用跳转
    navTo(route) {
      if (!this.profileInfo.phone) {
        this.$mRouter.push({ route });
      }
    },
    // 数据初始化
    initData(id) {
      this.getUserDetail(id);
    },
    async handleClick(){
     await this.$http.post(userDetail,this.unitinfo).then((r) => {
          this.loading = false;
          this.$mRouter.push({route:"/pages/user/userinfo/userinfo"})
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 获取用户信息
    async getUserDetail(id) {
      await this.$http
        .get(userDetail)
        .then((r) => {
          this.loading = false;
          if(r.data){
             this.unitinfo = r.data;
          }
          this.unitinfo.id =id
          console.log(r);
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
page {
  background: #f9f9f9;
}

.userinfo {
  border-top: 1upx solid #eeeeee;
  background: #ffffff;
  .right-row {
    width: 18upx;
    height: 18upx;
    border-top: 2upx solid #999999;
    border-right: 2upx solid #999999;
    transform: rotate(45deg);
  }

  .unit-text {
    font-size: 28upx;
    font-weight: 500;
    color: #999999;
  }
  .input-items {
    display: flex;
    border-bottom: 1upx solid #eeeeee;
    align-items: center;
    justify-content: flex-start;
    margin: 0 30upx 0 30upx;
    height: 100upx;
    font-size: 28upx;
    font-weight: 500;
    line-height: 100upx;
    color: #333333;
    &:last-child {
      margin-bottom: 0;
    }
    .tit {
      padding-right: 50upx;
    }
  }
  .btn-wrapper {
    margin: 135upx 30upx;
    .add-btn {
      background: #f91c1c;
      border-radius: 40upx;
      font-size: 30upx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #ffffff;
    }
  }
}
</style>
